package com.specialtreasure.freightdepot.activity;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.app.core.activity.BaseNewActivity;
import com.app.core.util.ScreenUtils;
import com.app.core.view.LazyViewPager;
import com.astuetz.PagerSlidingTabStripLazy;
import com.specialtreasure.freightdepot.R;
import com.specialtreasure.freightdepot.adapter.InformationPageAdapter;
import com.specialtreasure.freightdepot.fragment.InformationHistoryFragment;
import com.specialtreasure.freightdepot.fragment.InformationTodayFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/8/7 0007.
 * 信息管理页面
 */

public class InformationManageActivity extends BaseNewActivity implements View.OnClickListener {

    public static final String TAG = "InformationManageActivity";
    private ImageView iv_back;
    private TextView tv_title;
    private PagerSlidingTabStripLazy psts_tabs;
    private LazyViewPager vp_pager;
    private List<Fragment> infos = new ArrayList<Fragment>();
    private InformationPageAdapter informationPageAdapter;
    private InformationTodayFragment informationTodayFragment=new InformationTodayFragment();
    private InformationHistoryFragment informationHistoryFragment=new InformationHistoryFragment();


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_informationmanage);
        initView();
        setData();
    }


    private void initView() {
        iv_back = (ImageView) findViewById(R.id.iv_back);
        tv_title = (TextView) findViewById(R.id.tv_title);
        psts_tabs = (PagerSlidingTabStripLazy) findViewById(R.id.psts_tabs);
        vp_pager = (LazyViewPager) findViewById(R.id.vp_pager);

        iv_back.setOnClickListener(this);
    }


    /**
     * 设置数据
     */
    private void setData() {
        infos.add(informationTodayFragment);
        infos.add(informationHistoryFragment);

        informationPageAdapter = new InformationPageAdapter(getSupportFragmentManager());
        //设置fragment
        informationPageAdapter.setInfos(infos);
        //设置导航文本
        String[] TITLES = {"已发布信息", "发布历史"};
        informationPageAdapter.setTITLES(TITLES);
        setTabsValue();
        vp_pager.setAdapter(informationPageAdapter);
        psts_tabs.setViewPager(vp_pager);
        vp_pager.setOffscreenPageLimit(2);


    }


    /**
     * 对PagerSlidingTabStrip的各项属性进行赋值。
     */
    private void setTabsValue() {
        // 设置Tab是自动填充满屏幕的
        psts_tabs.setShouldExpand(true);
        // 设置Tab的分割线是透明的
        psts_tabs.setDividerColor(Color.TRANSPARENT);
        // 设置Tab底部线的高度
        psts_tabs.setUnderlineHeight(ScreenUtils.dpToPx(mContext,1));
        // 设置Tab Indicator的高度
        psts_tabs.setIndicatorHeight(ScreenUtils.dpToPx(mContext,4));
        // 设置Tab标题文字的大小
        psts_tabs.setTextSize(ScreenUtils.dpToPx(mContext,16));
        // 设置Tab标题默认的颜色
        psts_tabs.setTextColor(getResources().getColor(R.color.common_474747));
        // 设置选中Tab标题的颜色
        psts_tabs.setSelectedTextColor(getResources().getColor(R.color.common_474747));
        // 设置Tab底部线的颜色
        psts_tabs.setUnderlineColor(getResources().getColor(R.color.common_BDBDB));
        // 设置Tab Indicator的颜色
        psts_tabs.setIndicatorColor(getResources().getColor(R.color.common_FFA57D));
        // 取消点击Tab时的背景色
        psts_tabs.setTabBackground(getResources().getColor(R.color.transparent));
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }


    @Override
    public String getActiviyName() {
        return TAG;
    }


}
